package com.example.demo5072.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.example.demo5072.pojo.Person;
import com.example.demo5072.pojo.User;
import com.example.demo5072.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/User")
public class UserController {

    @GetMapping
    @ResponseBody
    //在Controller 中 请求参数上添加@Validated 标签开启验证
    public String test2(@Validated Person person) {
        return person.toString();
    }


    @Resource
    UserService userService;

    @RequestMapping("/test")
    public String test(Model model) {
        List<User> userList = userService.findAll();
        model.addAttribute("users", userList);
        return "user";
    }

}
